package com.grudesign.stutrip.controller;


import com.grudesign.stutrip.common.ReturnInfo;
import com.grudesign.stutrip.entity.Po.AdminInfoPo;
import com.grudesign.stutrip.entity.Vo.adminQuery;
import com.grudesign.stutrip.service.AdminInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author wx
 * @since 2022-05-09
 */
@RestController
@RequestMapping("/adminInfo")
public class AdminInfoController {

    @Autowired
    private AdminInfoService adminInfoService;

    @PostMapping("addAdmin")
    public Object addAdmin(@RequestBody AdminInfoPo adminInfoPo){
        Object obj  = adminInfoService.addAdmin(adminInfoPo);
        return obj;
    }

    @PostMapping("adminList")
    public Object addAdmin(@RequestBody adminQuery adminQuery){
        Object obj  = adminInfoService.getQueryAdmin(adminQuery);
        return obj;
    }

    @PostMapping("editAdmin")
    public Object editAdmin(@RequestBody AdminInfoPo adminInfoPo){
        boolean isUp = adminInfoService.updateById(adminInfoPo);
        return isUp?new ReturnInfo("200","ok"):new ReturnInfo("-1","error");
    }
    @GetMapping("/{id}")
    public Object  getAdmin(@PathVariable("id") String id){
        AdminInfoPo admin = adminInfoService.getById(id);
        return  new ReturnInfo("200","ok").data("admin",admin);
    }

    @PostMapping("/loginAdmin")
    public  Object loginAdmin(@RequestBody AdminInfoPo adminInfoPo){
        Object obj =  adminInfoService.login(adminInfoPo);
        return obj;
    }

    @DeleteMapping("delAdmin/{adminId}")
    public  Object delAdmin(@PathVariable("adminId")String adminId){
        boolean isDel = adminInfoService.removeById(adminId);
        return isDel?new ReturnInfo("200","ok"):new ReturnInfo("-1","error");
    }
}

